﻿@model DataModel.Models.JournalModel
@using DataModel.Managers.SubManage

@{
    ViewBag.Title = "Group";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="@Url.Content("~/Content/journal.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/table.css")" rel="stylesheet" type="text/css" />

<script src="@Url.Content("~/Scripts/journal.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.json-2.3.js")" type="text/javascript"></script>
    
@if (ViewBag.groupExist)
{
    if (ViewBag.journalExist)
    {
        
<h3>Group @Model.Group.ToString()</h3>
<h3>@Model.Subject.FullName</h3>
    
<div class="filter">
    <form method="post">
    <select name="subj">
        @foreach (var subj in ViewBag.subjectList)
        {
            <option value="@subj.ShortName">@subj.ShortName</option>
        }
    </select>

    <span>from</span>
        <input type="text" class="tbx datepicker" name="from" value="@DateTime.Today.ToShortDateString()"/>
        <span>to</span>
        <input type="text" class="tbx datepicker" name="to" value="@DateTime.Today.AddDays(61).ToShortDateString()"/>

         <!--<a href="@Url.Action(Model.Group.ToString(),"Journal")" class="btn">Refresh</a>-->
        <input type="submit" class="btn" value="Refresh"/>
    </form>
</div>
    
    <div class="journal-students">
		    <div class="j-student"></div>
                @foreach (var row in Model.JournalRows)
                {
                        <div class="j-student">@row.Student.User.lastName</div>
                }
		    
    </div>
    
    
    
    
    
    
    
    
<div class="j-wrapper">
        <div class="journal">
            <div class="j-row j-header">
                @foreach (var day in Model.DateList)
                {
                    <div class="t-cell j-cell">@day.ToShortDateString()</div>
                }
            </div>

            @foreach (var row in Model.JournalRows)
            {
                <div class="j-row">
                    @{
                        for (int i = 0; i < Model.DateList.Count; i++)
                        {
                            var cell = row.JournalCells.FirstOrDefault(c => c.Date.CompareOnlyDate(Model.DateList[i]));
                            if (cell != null)
                            {
                            <div class="j-cell j-presence-@(cell.Presence??0) transition-middle " 
                                data-studentid="@row.Student.ID"
                                data-subjectid="@Model.Subject.SubjectID"
                                data-date="@Model.DateList[i].Ticks"><div class="j-cell-presence">@cell.Presence</div><div class="j-cell-mark">@cell.Mark</div></div>
                            }
                            else
                            {
                            <div class="j-cell j-presence-0 transition-middle" 
                                data-studentid="@row.Student.ID"
                                data-subjectid="@Model.Subject.SubjectID"
                                data-date="@Model.DateList[i].Ticks"><div class="j-cell-presence"></div><div class="j-cell-mark"></div></div>
                            }
                        }
                    }
                </div>
            }

            

    </div>
</div>
}
else
{
    <h2>journal is not exist for this group :(</h2>
}
}
else
{
    <h2>group is not exist</h2>
}